var mysql = require('mysql');
var config = require('../../config');

var pool = mysql.createPool({
    host: config.mysql.host,
    port: config.mysql.port,
    user: config.mysql.user,
    password: config.mysql.password,
    database: config.mysql.database
});

exports.query = function(sql, params, callback ){
    pool.getConnection(function(err, conn) {
        if(err) {
            callback(err, null, null);
        } else {
            conn.query(sql, params, function(qerr, values, fields) {
                //释放连接
                conn.release();
                //事件驱动回调
                callback(qerr, values, fields);
            });
        }
    });
};